package com.example.qjia.model;

import android.util.Log;

import com.example.qjia.Listener.LoadHolidayMessageListener;
import com.example.qjia.data.HolidayMessage;
import com.example.qjia.data.romotedata.AbsenceSlip;
import com.example.qjia.data.romotedata.ResponseData;
import com.example.qjia.util.retrofit.RetrofitNet;

import rx.Observable;
import rx.Observer;

/**
 * Created by ying_xiang on 2016/8/16.
 */
public class LoadHolidayMessageModelImp implements LoadHolidayMessageModel {
    android.os.Handler handler=new android.os.Handler();
    @Override
    public void loadHolidayMessage(final String aid,final LoadHolidayMessageListener loadHolidayMessageListener) {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {            //模拟网络请求


                new RetrofitNet().getAbsenseSlip(aid, new Observer<ResponseData<AbsenceSlip>>() {
                    @Override
                    public void onCompleted() {
                        System.out.println("finish");
                    }

                    @Override
                    public void onError(Throwable e) {
                        System.out.println("error");
                        Log.e("MAIN2",e.getLocalizedMessage()+"--"+e.getMessage());

                    }

                    @Override
                    public void onNext(ResponseData<AbsenceSlip> absenceSlipResponseData) {
                        AbsenceSlip absenceSlip=(AbsenceSlip)absenceSlipResponseData.getData();
                        System.out.println(absenceSlipResponseData.getMsg());
                        if(absenceSlipResponseData.getCode()==0){
                            loadHolidayMessageListener.onSuccess(absenceSlip);
                        }else {
                            loadHolidayMessageListener.onFail();
                        }



                    }
                });


                //loadHolidayMessageListener.onFail();


            }
        },1500);

    }
}
